<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <%@include file="inc/_header.jsp"%>
</head>
<body>
<c:set var="nav_register" value="true"></c:set>
<%@include file="inc/_nav.jsp"%>
<div class="container">
    <form id="mainForm">
        <table>
            <tr>
                <td>用户名:</td>
                <td>
                    <input name="username" type="text" class="form-control"/>
                </td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input id="password" name="password" type="password" class="form-control"/></td>
            </tr>
            <tr>
                <td>确认密码:</td>
                <td>
                    <input id="password1" type="password" class="form-control"/>
                </td>
            </tr>
            <tr>
                <td>邮箱:</td>
                <td>
                    <input id="email" name="email" type="email" class="form-control"/>
                </td>
            </tr>
            <tr>
                <td>邮箱验证码:</td>
                <td>
                    <input id="checkcode" name="checkcode" class="form-control" />
                </td>
                <td>
                    <input id="sendCheckcode" type="button" class="btn btn-default" value="发送验证码" />
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center;">
                    <input type="submit" class="btn btn-default" value="提交">
                    已有账号?<a href="/user/login.do">登录</a>
                </td>
            </tr>
        </table>

    </form>
</div>

<script>
    $(function(){
        $("#sendCheckcode").on("click",function(){
            var email = $("#email").val();
            var param = {};
            param.email = email;
            $.post("/email/sendEmailCheckcode.do",param,function(result){
                if(result.success){
                    $("#sendCheckcode").hide();
                }else{
                    alert("出错了("+result.msg+")");
                }
            },"json").error(function(){
                alert("系统错误,请稍后重试");
            });
        });
        $("#mainForm").submit(function(data){



            var param = $(this).serializeArray();
            $.post("/user/register.do?method=send",param,function(result){
                if(result.success){
                    alert("注册成功");
                }else{
                    alert("注册失败:"+result.msg);
                }
            },"json").error(function(){
                alert("系统错误,请刷新后重试");
            })
            return false;
        })

    })
</script>
</body>
</html>
